package com.ddwl.data.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.data.mapper.ProtocolConfigMapper;
import com.ddwl.data.model.ProtocolConfig;
import com.ddwl.schema.bo.data.QueryProtocolConfigBo;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author wenbin
 * @Date 2020/9/17 11:42
 */

@Repository
public class ProtocolConfigDao extends TkDao<ProtocolConfigMapper, ProtocolConfig> {

    @Resource
    private ProtocolConfigMapper protocolConfigMapper;

    public ProtocolConfig getProtocolConfig(QueryProtocolConfigBo bo) {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setStatus(bo.getStatus());
        protocolConfig.setType(bo.getType());
        return this.selectOne(protocolConfig);
    }

    public List<ProtocolConfig> getList(QueryProtocolConfigBo bo) {
        Example example = getExample();
        if (bo.getType() != null) {
            example.and().andEqualTo("type", bo.getType());
        }
        if (bo.getStatus() != null) {
            example.and().andEqualTo("status", bo.getStatus());
        }
        return protocolConfigMapper.selectByExample(example);
    }

}
